package leetcode.code0204;

import java.util.ArrayList;
import java.util.List;

public class Solution2 extends Solution204 {

	@Override
	public int countPrimes(int n) {
		boolean[] dp = new boolean[n];
		List<Integer> primes = new ArrayList<>();
		for (int i = 2; i < n; i++) {
			if (!dp[i]) {
				primes.add(i);
			}
			for (int j = 0; j < primes.size(); j++) {
				int prime = primes.get(j);
				if (prime * i >= n) {
					break;
				}
				dp[prime * i] = true;
				if (i % prime == 0) {
					break;
				}
			}
		}
		return primes.size();
	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
	}

}
